
public class Time implements Comparable
{

   private int hour;
   private int minute;
   private boolean morning;

   public Time(int hour, int minute, boolean morning)
   {
      this.hour = hour;
      this.minute = minute;
      this.morning = morning;
   }

   public int getHour()
   {
      return hour;
   }

   public int getMinute()
   {
      return minute;
   }

   public boolean isMorning()
   {
      return morning;
   }
   public String toString()
   {
      String result = "";
      
      if(minute<10)
         result = hour+":0"+minute;
      else
         result = hour+":"+minute;
      
      if(isMorning())
      {
         return result+"am";
      }
      else
      {
         return result+"pm";
      }
   }

   public int compareTo(Object o)
   {
      if(!(o instanceof Time))
         throw new ClassCastException("Time Object expected.");
      
      Time aTime = (Time)o;
      
      int atimehour = aTime.getHour();
      int thistimehour = hour;
      
      if(!this.isMorning())
      {
         thistimehour+=12;
      }
      if(!aTime.isMorning())
      {
         atimehour+=12;
      }
      if(thistimehour - atimehour == 0)
      {
         return this.getMinute() - aTime.getMinute();
      }
      return thistimehour-atimehour;
   }
}
